package com.cunshe.web.manage;

import com.cunshe.common.ResponseVO;
import com.cunshe.config.annotation.Login;
import com.cunshe.domain.ProductImage;
import com.cunshe.entity.vo.ProductImageInsertVO;
import com.cunshe.service.ProductImageService;
import com.sunkee.commons.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品图片
 * @author xiao
 */
@Api(tags = "产品图片")
@Login
@RestController
@RequestMapping(value = "/manage/productImage")
public class ProductImageController {

    @Autowired
    private ProductImageService productImageService;

    /** 新增 */
    @ApiOperation(value = "新增")
    @PostMapping(value = "insert")
    public ResponseVO insert(@RequestBody @Validated ProductImageInsertVO vo) {
        ProductImage record = ConvertUtil.copyProperties(vo, ProductImage.class);
        productImageService.insert(record);
        return ResponseVO.success();
    }

    /** 删除 */
    @ApiOperation(value = "删除")
    @PostMapping(value = "delete")
    public ResponseVO delete(@RequestParam("id") Long id) {
        productImageService.delete(id);
        return ResponseVO.success();
    }

    /** 查询产品图片 */
    @ApiOperation(value = "查询列表")
    @PostMapping(value = "getProductImage")
    public ResponseVO getProductImage(@RequestParam("productId") Long productId) {
        List<ProductImage> list = productImageService.getProductImage(productId);
        return ResponseVO.success(list);
    }

}